///
/// This is the main() for the Client
///

#include <iostream>
#include <netdb.h>
#include <arpa/inet.h>
#include <cstring>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <cassert>
#include "common.h"
//#include <cstdio>
#include "Handler.h"
#include "Client.h"

int main(int argc, char** argv)
{

	//make sure you're called correctly
	if(argc != 4)
	{
		std::cout << "Usage: ./client serverIP serverPort uri" << std::endl;
		return 1;
	}
	
	const char* uri = argv[3];
	if(!((uri[0] == 'h') && (uri[1] == 't') && (uri[2] == 't') 
		&& (uri[3] == 'p') && (uri[4] == ':') && (uri[5] == '/') 
		&& (uri[6] == '/')))
	{
		std::cout << "Please enter the URI as: http://xxx.yyy.zzz\n";
		return 0;
	}
	
	Client* client = Client::GetInstance();
	client->Initialize(argv[1], argv[2], argv[3]);
	
	client->Execute();

	Client::Destroy();

	return 0;
}
